<%--
  Created by IntelliJ IDEA.
  User: hklyq
  Date: 2019-03-01
  Time: 16:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>添加诉讼记录</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <form id="formSet1">
        <div class="fieldset1 tabel_col clearFix">
            <div class="fieldBox col_50">
                <div class="label">创建时间</div>
                <div class="field">
                    <input disabled="disabled" class="ui-textbox" id="crtTm" name="crtTm" value="${crtTm}">
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">创建人</div>
                <div class="field">
                    <input type="text" id="crtUsrNm" name="crtUsrNm" class="ui-textbox"
                           disabled="disabled" value="${crtUsrNm}"/>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">诉讼进度</div>
                <div class="field">
                    <select name="sueProgress" id="sueProgress" validate="{required:true,select:true}" onchange="changeValue();">
                        <option selected value="  ">请选择</option>
                        <c:forEach items="${sueProgress}" var="signResCd">
                            <option value="${signResCd.key}">${signResCd.value}</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">判决结果</div>
                <div class="field">
                    <select name="judgeRstCd" id="judgeRstCd" onchange="changeResValue();">
                        <option selected value="  ">请选择</option>
                        <c:forEach items="${sueRes}" var="signResCd">
                            <option value="${signResCd.key}">${signResCd.value}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">调解结果</div>
                <div class="field">
                    <textarea name="mediationResult" id="mediationResult" rows="3" class="l-textarea" style="width:98%"
                              value=""></textarea>
                </div>
            </div>
            <div class="fieldBox col_50 isPrivate">
                <div class="label">案件编号</div>
                <div class="field">
                    <input type="text" id="caseNo" name="caseNo" class="ui-textbox" value="${sue.caseNo}"/>
                </div>
            </div>
            <div class="fieldBox col_50 isPrivate">
                <div class="label">开庭时间</div>
                <div class="field">
                    <input name="courtTm" id="courtTm" type="text" class="ui-datepicker" value="" >
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">管辖法院</div>
                <div class="field">
                    <input type="text" id="courtNm" name="courtNm" class="ui-textbox" value="${sue.courtNm}"/>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">立案时间</div>
                <div class="field">
                    <input name="registTm" id="registTm" type="text" class="ui-datepicker" value="${regisTm}" value="">
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">庭审法官</div>
                <div class="field">
                    <input type="text" id="judgeName" name="judgeName" class="ui-textbox"  value="${sue.judgeName}"/>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">法官手机号</div>
                <div class="field">
                    <input type="text" id="judgeTel" name="judgeTel" class="ui-textbox"  value="${sue.judgeTel}"/>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">书记员</div>
                <div class="field">
                    <input type="text" id="clerkName" name="clerkName" class="ui-textbox"  value="${sue.clerkName}"/>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">书记员手机号</div>
                <div class="field">
                    <input type="text" id="clerkTel" name="clerkTel" class="ui-textbox"  value="${sue.clerkTel}"/>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">判决时间</div>
                <div class="field">
                    <input name="judgeTm" id="judgeTm" type="text" class="ui-datepicker" value="">
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">生效时间</div>
                <div class="field">
                    <input name="effectStDt" id="effectStDt" type="text" class="ui-datepicker" value="">
                    <span>-</span>
                    <input name="effectEdDt" id="effectEdDt" type="text" class="ui-datepicker" value="">
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">结案状态</div>
                <div class="field">
                    <input name="caseRes" id="caseRes" placeholder="请选择" ltype="combobox" >
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label"></div>
                <div class="field"></div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">执行法官</div>
                <div class="field">
                    <input type="text" id="execJudgeName" name="execJudgeName" class="ui-textbox" value="${sue.execJudgeName}"/>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">执行法官手机号</div>
                <div class="field">
                    <input type="text" id="execJudgeTel" name="execJudgeTel" class="ui-textbox"  value="${sue.execJudgeTel}"/>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">其他说明</div>
                <div class="field">
                    <textarea name="sueRem" id="sueRem" rows="3" class="l-textarea" style="width:98%"
                              value=""></textarea>
                </div>
            </div>
        </div>
        <div class="fieldset1 tabel_col clearFix">
            <div id="ligergrid1" class="sq-grid"></div>
        </div>
        <div class="fieldset1 tabel_col clearFix">
            <div class="sqPanel_body">
                <div id="sueBscInfoFileCfgGrid" class="sq-grid"></div>
            </div>
            <div id="noticeDIV" class="fieldBox col_100">
                <div class="label"></div>
                <div class="field">
                    <span name="" id="" style="color: red;">注意：诉讼记录保存后不可删除，请注意信息准去性</span>
                </div>
            </div>
        </div>
        <div class="btnsBox">
            <span id="saveBtn" class="sq-button sq-button-round" onclick="save();">保存诉讼状态</span>
            <span id="startFlow" class="sq-button sq-button-round" onclick="startConcludeFlow();">提交结案审批</span>
        </div>
    </form>
</div>


<script type="text/javascript">
    var applyId = '${applyId}';
    var taskFlag = '${taskFlag}';
    var sueBscInfoFileCfgGrid = null;
    var grid = null;
    // 预先获取的诉讼基础信息的id
    var id = '${id}';
    var processCd = '${sue.processCd}';

    $(function () {
        var formSet1 = $('#formSet1').ligerForm({
            validate: true
        });
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/sue/sueBscInfo/initSuePayDtl.do?applyId=' + applyId,
            method: 'get',
            columns: [
                {
                    display: '支付表号', name: 'paySchNo', minWidth: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '<a href="javascript:showPaySchDetail('+rowdata.paySchId+','+"'"+rowdata.tableNm+"'"+')"'+'class="link">'+rowdata.paySchNo+'</a>';
                    }

                },
                {display: '支付表状态', name: 'prdStsNm', minWidth: 80, align: 'center', enabledSort: false},
                {
                    display: '判决结果', name: 'judgeResult', minWidth: 200, align: 'center', enabledSort: false,type: 'text',
                    editor: { type: 'text', valueField: 'value', textField: 'name' }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            enabledEdit: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);



        //项目资料Grid
        sueBscInfoFileCfgGrid = $("#sueBscInfoFileCfgGrid").ligerGrid({
            url: '<%=path%>/sue/sueBscInfo/initSueBscInfoFileCfgGrid.do?id=' + id,
            method: 'get',
            columns: [
                {display: '资料名称', name: 'datNm', align: 'center', minWidth: 100, enabledSort: false},
                {
                    display: '上传文件名称', name: 'fileNm', minWidth: 100, enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        if (value) {
                            var h;
                            h = '<a href="javascript:uploadFileByUrl(';
                            h += "'" + rowdata.filePath + "'";
                            h += ",'" + rowdata.fileNm + "'";
                            h += ')">' + rowdata.fileNm + '</a>'
                            return h;
                        }
                    }
                },
                {
                    display: '上传时间',
                    name: 'crtTm',
                    align: 'center',
                    minWidth: 100,
                    enabledSort: false,
                    render: renderDate
                },
                {display: '上传用户', name: 'upUsrNm', width: 100, enabledSort: false},
                {
                    display: '操作', name: '', minWidth: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="delFile(event,' + rowdata.fileId + ');"><i class="sqBtnIco_7"></i>删除</a>';
                        return h;
                    }
                },
                {
                    display: '上传', name: 'uploadNm', width: 80, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        h += '<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '" multiple name="fileup_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '"' +
                            ' class="fileupload-input" onchange="onChangefile_multi(event,\'' + rowdata.cfgCd + '\',\'' + rowdata.cfgDtlCd + '\',\'' + rowdata.orgCd + '\');"></span>';
                        return h;
                    }
                },
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            onAfterShowData: function () {
                $('#sueBscInfoFileCfgGrid').rowspan('datNm');
                $('#sueBscInfoFileCfgGrid').rowspan('uploadNm');
            },
        });

        $("#caseRes").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("caseRes").setData(${caseResJSON});

        if (null != processCd && '' != processCd) {
            // liger.get("courtNm").setDisabled(true);
            // liger.get("registTm").setDisabled(true);
            // liger.get("caseNo").setDisabled(true);
        }

        if (StringUtils.isNotEmpty(taskFlag)) {
            $("#startFlow").hide();
        }

    });

    function uploadFileByUrl(_url,_name){
        if(SQ.regs.img.test(_name)){
            //SQ.imgPreview(_url);
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '诉讼资料', 'location=yes, width=800, height=600');
        }else{
            window.open(_url);
        }
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    function onChangefile_multi(e, cfgCd, cfgDtlCd, orgCd) {
        var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        var filePath = "";
        filePath = "sueBscInfo";

        $.ajaxFileUpload({
            url: '<%=path%>/system/sysulfilesrec/upload.do',
            secureuri: false,
            fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
            dataType: 'json',
            data: {filePath: filePath},
            success: function (msg) {
                if (msg.success == 1) {
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {
                            'fileParams': JSON.stringify(msg.data),
                            'id': id,
                            'cfgCd': cfgCd,
                            'cfgDtlCd': cfgDtlCd,
                            'orgCd': orgCd
                        },
                        url: '<%=path%>/sue/sueBscInfo/uploadSueBscInfoFile.do',
                        success: function (msg) {
                            if (msg.success == 1) {
                                sueBscInfoFileCfgGrid.reload();
                            } else {
                                $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                            }
                            $.ligerDialog.hide();
                        }
                    });
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    };

    // 删除文件
    function delFile(event, _fileId) {
        top.$.ligerDialog.confirm("确认删除吗?", function (flag) {
            if (!flag) {
                return;
            } else {
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fileId': _fileId},
                    url: '<%=path%>/project/prjFileInfo/removeFile.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        if (msg.success == 1) {
                            wait_dialog.close();
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            parent.$('li[tabid="mateTab"] a').text('项目资料(' + msg.data + ')');
                            event.stopPropagation();
                            var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                            liger.get(gridID).reload();
                        } else {
                            wait_dialog.close();
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            }
        });
    }

    // 根据诉讼进度修改其他地方的值
    function changeValue() {
        // 诉讼进度
        var sueProgressCd = $('#sueProgress').val();
        // 修改结案状态
        $.each(${caseResJSON}, function (i, o) {
            if ('0008' === sueProgressCd) {
                if ('0001' === o.key) {
                    $("#caseRes").val(o.value);
                    $("#caseRes").selected = true;
                }
            }
        });

        if ('0004' === sueProgressCd && '0004' != processCd) {
            liger.get("courtNm").setEnabled();
            liger.get("registTm").setEnabled();
            liger.get("caseNo").setEnabled();
        }
    }

    // 根据判决结果修改支付表的判决结果
    function changeResValue() {
        // 诉讼进度
        var judgeRstCd = $('#judgeRstCd').val();
        if ('0002' === judgeRstCd) {
            var rows = grid.rows;
            for (var i = 0; i < rows.length; i++) {
                grid.updateRow(rows[i], {
                    judgeResult: '解除合同'
                });
            }
        }
    }

    // 保存
    function save() {
        var form = liger.get("formSet1");
        if (!form.valid()) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var paySchData = grid.getData();

        // 诉讼进度
        var sueProgressCd = $('#sueProgress').val();
        // 判决时间
        var judgeTm = $('#judgeTm').val();
        // 判决结果
        var judgeRstCd = $('#judgeRstCd').val();
        // 生效时间
        var effectStDt = $('#effectStDt').val();
        var effectEdDt = $('#effectEdDt').val();
        //手机号
        var judgeTel = $('#judgeTel').val();
        if(null != judgeTel && judgeTel != ""){
            if(!(/^1(3|4|5|7|8)\d{9}$/.test(judgeTel))){
                $.ligerDialog.SQalert({content: '庭审法官手机号码有误！', SQ_type: "warning"});
                return false;
            }
        }
        var clerkTel = $('#clerkTel').val();
        if(null != clerkTel && clerkTel!=""){
            if(!(/^1(3|4|5|7|8)\d{9}$/.test(clerkTel))){
                $.ligerDialog.SQalert({content: '书记员手机号码有误！', SQ_type: "warning"});
                return false;
            }
        }
        var execJudgeTel = $('#execJudgeTel').val();
        if(null !=execJudgeTel && execJudgeTel!=""){
            if(!(/^1(3|4|5|7|8)\d{9}$/.test(execJudgeTel))){
                $.ligerDialog.SQalert({content: '执行法官手机号手机号码有误！', SQ_type: "warning"});
                return false;
            }
        }

        // 已判决情况下需维护：判决时间、判决结果、生效时间
        if (sueProgressCd === '0005') {
            if ('  ' == judgeRstCd || null == judgeRstCd) {
                $.ligerDialog.SQalert({content: '请选择判决结果！', SQ_type: "warning"});
                return false;
            }
            if ('' == judgeTm || null == judgeTm) {
                $.ligerDialog.SQalert({content: '请选择判决时间！', SQ_type: "warning"});
                return false;
            }
            if ('' == effectStDt || null == effectStDt || '' == effectEdDt || null == effectEdDt) {
                $.ligerDialog.SQalert({content: '请选择生效时间！', SQ_type: "warning"});
                return false;
            }
        }
        // 诉讼进度是执行完毕情况下判决结果必须有结果
        if (sueProgressCd === '0008') {
            if ('  ' == judgeRstCd || null == judgeRstCd) {
                $.ligerDialog.SQalert({content: '请选择判决结果！', SQ_type: "warning"});
                return false;
            }
        }
        // 调解结果
        var mediationResult = $('#mediationResult').val();
        // 诉讼进度是已调解情况下判决结果和调解结果必须选
        if (sueProgressCd === '0006') {
            if ('  ' == judgeRstCd || null == judgeRstCd) {
                $.ligerDialog.SQalert({content: '请选择判决结果！', SQ_type: "warning"});
                return false;
            }
            if ('' == mediationResult || null == mediationResult) {
                $.ligerDialog.SQalert({content: '请维护调解结果！', SQ_type: "warning"});
                return false;
            }
        }

        var data = form.getData();
        data['id'] = id;
        data['applyId'] = applyId;
        data['paySchData'] = JSON.stringify(paySchData);
        var url = '<%=path%>/sue/sueBscInfo/add.do';
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            success: function (msg) {
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    setTimeout(function(){ frameElement.dialog.close(); }, 1500);
                    parent.grid.reload();
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    /**
     * 发起结案审批流程
     */
    function startConcludeFlow() {
        var wait_dialog;
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '<%=path%>/sue/sueBscInfo/startCaseFinishedFlow.do?applyId=' + applyId,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({
                    content: LogUtils.LOG_CMM_DATA_LOADING,
                    SQ_type: "waitting"
                });
            },
            success: function (msg) {
                if (msg.success == 1) {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    setTimeout(function () {
                        frameElement.dialog.close();
                    }, 1500);
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    /**
     * 查看支付表信息
     * @param paySchId
     */
    function showPaySchDetail(paySchId, tableNm){
        if ('PRJ_PRD_PAY_SCH_M' === tableNm) {
            $.ajax({
                type: 'get',
                dataType: 'json',
                url: '<%=path%>/risk/ovdCollect/getPayInfo.do?paySchId=' + paySchId,
                success: function (msg) {
                    if (msg.success == 1) {
                        Add_navTab('tab_prj_quat_prps' + paySchId, '查看支付表', '/web/project/prjprdpayschm/toAddPage.do?prjId=' + msg.data.prjId + '&&id=' + paySchId + '&&prjPrdDtlId=' + msg.data.prjPrdDtlId + '&&prjPrdId=' + msg.data.prjPrdId + '&&detailFlag=true');
                    }
                }
            });
        } else if ('MCR_BILL_M' === tableNm) {
            Add_navTab('MCR_BILL_M_'+billId,'小贷账单详情',"<%=path%>/mcr/mcrBillM/toBillDtlPage.do?id="+paySchId);
        }
    }


</script>

</body>
</html>

